package com.vcg.comment.support.exception;

import com.alibaba.fastjson.JSONObject;
import com.vcg.comment.support.data.CommentResult;
import org.springframework.core.MethodParameter;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.method.HandlerMethod;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Date;

/**
 * Created by wuyu on 2016/6/1.
 * 处理访问异常
 */
@ControllerAdvice
public class CommentExceptionResolver {


    @ExceptionHandler(Exception.class)
    @ResponseBody
    public JSONObject resolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {
        ex.printStackTrace();
        return new CommentResult()
                .setStatus(500)
                .setMsg(ex.getMessage())
                .setTimestamp(new Date())
                .toJSONObject();
    }
}
